function ecog = bciCalib(ratioThresh)

% bciCalib records a data segment of 10sec. It is recommended that the 
% Subject closes his eyes and does not move to prevent artifacts.
% Currently data are just visualized to help find noisy channels and
% determine adequate artifact threshold
%
% channel numbers listed in white are bad channels according to the ratio 
% threshold criterion  
% ratioThresh defines the ratio threshold for bad channels.  The ratio is
% std(per channel)/mean(std(all channels)). Default is 6 fold increased
% standard deviation. This parameter can be passed as an argument
%
% todo: automatically apply badChan data and artifact threshold (requires
% reliable estimates)
% requires: ecog toolbox, chronux toolbox
% see also: bciPlotVariances, bciRecordCalibData
%

if nargin<1
    ratioThresh = 4;
end
[ecog,bci] = bciRecordCalibData();
bciPlotVariances(ecog,bci,ratioThresh);

drawnow
figure;plot(std(ecog.data')); axis tight
title('Standard deviation of time series')
ylabel('Standard deviation')
xlabel('Channel number')
drawnow

params.Fs=1000/ecog.sampDur;
params.fpass=[1 200];
params.tapers=[4 7];
params.trialave=0; 
ecog=ecogMkPeriodogramMultitaper(ecog,1,params);
figure;plot(ecog.periodogram.centerFrequency,log(ecog.periodogram.periodogram));
xlabel('Frequency [Hz]')
ylabel('log(Amplitude)')
